package org.autumn.review.thread;

import com.mysql.cj.xdevapi.TableImpl;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

public class Visibility {
    public  static boolean flag = true;


    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true){
                // always run
                synchronized (Visibility.class){
                    if (!flag){
                        break;
                    }
                }
            }
        }, "t1");
        t1.start();


        TimeUnit.SECONDS.sleep(1);

        flag = false;
    }

    private static void alwaysRun() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (flag){
                // always run
            }
        }, "t1");
        t1.start();


        TimeUnit.SECONDS.sleep(1);

        flag = false;
    }
}
